{% extends "base_project.html" %}
{% load humanize static hc_extras %}

{% block title %}Mattermost Integration for {{ site_name }}{% endblock %}
{% block description %}
    <meta name="description" content="If your team uses Mattermost, you can set up {{ site_name }} to post alerts directly to an appropriate Mattermost channel when a check goes up or down.">
{% endblock %}

{% block content %}
<div class="row">
<div class="col-sm-12">

    <h1>Mattermost</h1>
    <div class="jumbotron">
        {% if request.user.is_authenticated %}
        <p>
            If your team uses <a href="https://mattermost.com/">Mattermost</a>,
            you can set up {{ site_name }} to post alerts directly to an
            appropriate Mattermost channel when a check goes <strong>up</strong>
            or <strong>down</strong>.
        </p>
        {% else %}
        <p>
            {{ site_name }} is a free and
            <a href="https://github.com/healthchecks/healthchecks">open source</a>
            service for monitoring <strong>cron jobs</strong>, <strong>background processes</strong> and
            <strong>scheduled tasks</strong>. When {% site_name %} detects a problem, it can notify
            you by posting to a Mattermost channel. To set up the Mattermost
            integration, please log into {{ site_name }}:
        </p>

        <div class="text-center">
            <a href="{% url 'hc-login' %}"
               class="btn btn-primary btn-lg">Log In</a>
        </div>
        {% endif %}
    </div>

    <h2>Setup Guide</h2>

    <div class="row ai-step">
        <div class="col-sm-6">
            <span class="step-no"></span>
            Log into your Mattermost account and
            select <strong>Integrations</strong> in the
            top left menu.
        </div>
        <div class="col-sm-6">
            <img
                class="ai-guide-screenshot"
                alt="Screenshot"
                src="{% static 'img/setup_mattermost_1.png' %}">
        </div>
    </div>
    <div class="row ai-step">
        <div class="col-sm-6">
            <span class="step-no"></span>
            <p>
            In the "Integrations" screen, select <strong>Incoming Webhook</strong>
            and then <strong>Add Incoming Webhook</strong>.
            </p>
            <p>Fill in the form and hit "Save".</p>
        </div>
        <div class="col-sm-6">
            <img
                class="ai-guide-screenshot"
                alt="Screenshot"
                src="{% static 'img/setup_mattermost_2.png' %}">
        </div>
    </div>

    <div class="row ai-step">
        <div class="col-sm-6">
            <span class="step-no"></span>
            {% if project %}
            <p>Copy the displayed <strong>URL</strong> and paste it in the form below.</p>
            <p>Save the integration, and you are all set!</p>
            {% else %}
            <p>Copy the displayed <strong>URL</strong>.</p>
            {% endif %}
        </div>
        <div class="col-sm-6">
            <img
                class="ai-guide-screenshot"
                alt="Screenshot"
                src="{% static 'img/setup_mattermost_3.png' %}">
        </div>
    </div>

    {% if not project %}
    <div class="row ai-step">
        <div class="col-sm-6">
            <span class="step-no"></span>
            <p>Log into {% site_name %}, then go to the <strong>Integrations</strong>
                page and click on <strong>Add Integration</strong> next to the
                Mattermost integration.
            </p>
        </div>
        <div class="col-sm-6">
            <img
                class="ai-guide-screenshot"
                alt="Screenshot"
                src="{% static 'img/setup_mattermost_4.png' %}">
        </div>
    </div>

    <div class="row ai-step">
        <div class="col-sm-6">
            <span class="step-no"></span>
            <p>Paste the copied <strong>URL</strong> in the form.</p>
            <p>Save the integration, and you are all set!</p>
        </div>
        <div class="col-sm-6">
            <img
                class="ai-guide-screenshot"
                alt="Screenshot"
                src="{% static 'img/setup_mattermost_5.png' %}">
        </div>
    </div>
    {% endif %}

    {% if project %}
    <h2>Integration Settings</h2>
    <form method="post" class="form-horizontal">
        {% csrf_token %}
        <div class="form-group {{ form.value.css_classes }}">
            <label for="callback-url" class="col-sm-2 control-label">
                Webhook URL
            </label>
            <div class="col-sm-10">
                <input
                    id="callback-url"
                    type="text"
                    class="form-control"
                    name="value"
                    placeholder="https://"
                    value="{{ form.value.value|default:"" }}">

                {% if form.value.errors %}
                <div class="help-block">
                    {{ form.value.errors|join:"" }}
                </div>
                {% endif %}
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-primary">Save Integration</button>
            </div>
        </div>
    </form>
    {% endif %}
</div>
</div>
{% endblock %}
